package com.example.auth.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.auth.entity.SysRolePermissionEntity;
import com.example.auth.service.SysRolePermissionService;
import com.example.mallcommon.RestResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 角色资源映射
 *
 * @author yang
 * @date 2021-08-23 23:45:48
 */
@ApiOperation("角色资源映射")
@RestController
@AllArgsConstructor
@RequestMapping("/sysrolepermission")
public class SysRolePermissionController {

    @Autowired private final  SysRolePermissionService sysRolePermissionService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param sysRolePermission 角色资源映射
     * @return
     */
    @ApiOperation("分页查询")
    @RequestMapping(value="/page",method = RequestMethod.GET)
    public RestResult<IPage<SysRolePermissionEntity>> getSysRolePermissionPage(Page page, SysRolePermissionEntity sysRolePermission) {
        return  new RestResult<>(sysRolePermissionService.page(page,Wrappers.query(sysRolePermission)));
    }


    /**
     * id查询角色资源映射
     * @param id id
     * @return RestResult
     */
    @ApiOperation("通过id查询角色资源映射")
    @ApiImplicitParam(name = "uid",value = "角色资源映射编码", required = true,paramType = "path")
    @RequestMapping(value="/{id}",method = RequestMethod.GET)
    public RestResult<SysRolePermissionEntity> getById(@PathVariable("id") String id){
        return new RestResult<>(sysRolePermissionService.getById(id));
    }

    /**
     * 新增角色资源映射
     * @param sysRolePermissionEntity 角色资源映射
     * @return RestResult
     */
    @ApiOperation("新增角色资源映射")
    @ApiImplicitParam(name = "sysRolePermission",value = "角色资源映射实体类", required = true,paramType = "body",dataType="SysRolePermissionEntity")
    @RequestMapping(method = RequestMethod.POST)
    public RestResult save(@RequestBody SysRolePermissionEntity sysRolePermissionEntity){
        return new RestResult<>(sysRolePermissionService.save(sysRolePermissionEntity));
    }

    /**
     * 修改角色资源映射
     * @param sysRolePermissionEntity 角色资源映射
     * @return RestResult
     */
    @ApiOperation("修改角色资源映射")
    @RequestMapping(method = RequestMethod.PUT)
    @ApiImplicitParam(name = "sysRolePermission",value = "角色资源映射实体类", required = true,paramType = "body",dataType="SysRolePermissionEntity")
    public RestResult updateById(@RequestBody SysRolePermissionEntity sysRolePermissionEntity){
        return new RestResult<>(sysRolePermissionService.updateById(sysRolePermissionEntity));
    }

    /**
     * 通过id删除角色资源映射
     * @param id id
     * @return RestResult
     */
    @ApiOperation("删除角色资源映射")
    @ApiImplicitParam(name = "uid",value = "角色资源映射编码", required = true,paramType = "path")
    @RequestMapping(value="/{id}",method = RequestMethod.DELETE)
    public RestResult removeById(@PathVariable String id){
        return new RestResult<>(sysRolePermissionService.removeById(id));
    }

    /**
     * 查询全部
     * @param
     * @return RestResult
     */
    @ApiOperation("查询全部")
    @RequestMapping(value="/queryAll",method = RequestMethod.GET)
    public RestResult<List<SysRolePermissionEntity>> queryAll(){
        return new RestResult<>(sysRolePermissionService.list());
    }

}